home *** CD-ROM | disk | FTP | other *** search
/ Freelog 22 / freelog 22.iso / Prog / Djgpp / GPC2952B.ZIP / doc / gpc / demos / bigmemdemo.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  2001-02-08  |  2.7 KB  |  89 lines

  1. {
  2. GPC demo program for the BigMem routines.
  3. Uniform access to big memory blocks for GPC and BP.
  4.  
  5. Copyright (C) 1999-2001 Free Software Foundation, Inc.
  6.  
  7. Author: Frank Heckenbach <frank@pascal.gnu.de>
  8.  
  9. This program is free software; you can redistribute it and/or
  10. modify it under the terms of the GNU General Public License as
  11. published by the Free Software Foundation, version 2.
  12.  
  13. This program is distributed in the hope that it will be useful,
  14. but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. GNU General Public License for more details.
  17.  
  18. You should have received a copy of the GNU General Public License
  19. along with this program; see the file COPYING. If not, write to
  20. the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  21. Boston, MA 02111-1307, USA.
  22.  
  23. As a special exception, if you incorporate even large parts of the
  24. code of this demo program into another program with substantially
  25. different functionality, this does not cause the other program to
  26. be covered by the GNU General Public License. This exception does
  27. not however invalidate any other reasons why it might be covered
  28. by the GNU General Public License.
  29. }
  30.  
  31. program BigMemDemo;
  32.  
  33. uses GPC {$ifdef __GPC__}, GPCUtil {$endif};
  34.  
  35. type
  36.   TStr = String {$ifdef __GPC__} ($fff7) {$endif};
  37.  
  38. const
  39.   BlockNumber = 1000;
  40.   BlockSize = SizeOf (TStr);
  41.  
  42. var
  43.   BigMem : PBigMem;
  44.   s : TStr;
  45.   p : ^TStr;
  46.   i : Integer;
  47.  
  48. begin
  49.   Writeln ('Trying to allocate ', BlockNumber, ' blocks of ', BlockSize, ' bytes each.');
  50.   BigMem := AllocateBigMem (BlockNumber, BlockSize, True);
  51.   if BigMem^.Number = 0 then
  52.     begin
  53.       Writeln (StdErr, 'Could not allocate any blocks. Please make available some more memory.');
  54.       Halt (1)
  55.     end;
  56.   Writeln ('Allocated ', BigMem^.Number, ' blocks.');
  57.   Writeln;
  58.   Writeln ('Enter some strings up to ', GetStringCapacity (s), ' characters each to');
  59.   Writeln ('copy into the blocks (empty string when finished).');
  60.   for i := 1 to BigMem^.Number do
  61.     begin
  62.       Write ('Block #', i, ': ');
  63.       Readln (s);
  64.       MoveToBigMem (s, BigMem, i);
  65.       if s = '' then Break
  66.     end;
  67.   Writeln;
  68.   Writeln ('Copying back the strings from the blocks:');
  69.   for i := 1 to BigMem^.Number do
  70.     begin
  71.       MoveFromBigMem (BigMem, i, s);
  72.       if s = '' then Break;
  73.       Writeln ('Block #', i, ': ', s)
  74.     end;
  75.   Writeln;
  76.   Writeln ('Press enter.');
  77.   Readln;
  78.   Writeln ('Now mapping the blocks and reading the strings directly:');
  79.   for i := 1 to BigMem^.Number do
  80.     begin
  81.       p := MapBigMem (BigMem, i);
  82.       if p^ = '' then Break;
  83.       Writeln ('Block #', i, ': ', p^)
  84.     end;
  85.   Writeln;
  86.   Writeln ('Deallocating memory blocks.');
  87.   DisposeBigMem (BigMem)
  88. end.
  89.